package com.thug.entities;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.AnimatedSprite;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.thug.engine.BaseGameEntity;

public class Gold extends BaseGameEntity {
	
	AnimatedSprite mSprite;
	Body mBody;
	boolean mPlayerTouched;
	
	public Gold(AnimatedSprite s, Body b) {
		mEntityType = EntityType.ET_GOLD;
		mSprite = s;
		mBody = b;
		mPlayerTouched = false;
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attach(Scene scene) {
		scene.attachChild(mSprite);
	}

	@Override
	public void detach(Scene scene) {
		scene.detachChild(mSprite);
	}

	@Override
	public void update(float elapsedTime) {
		if(mPlayerTouched == true){
			setActive(false);
			mSprite.setVisible(false);
			mBody.setActive(false);
		}
		
	}

	@Override
	public void beginContact(Body bodyA, Body bodyB, Vector2 normal,
			Vector2[] points) {
		BaseGameEntity entityA = (BaseGameEntity) bodyA.getUserData();
		BaseGameEntity entityB = (BaseGameEntity) bodyB.getUserData();
		
		if(entityA.getType() == EntityType.ET_PLAYER || entityB.getType() == EntityType.ET_PLAYER) {
			mPlayerTouched = true;
		}
			
		
	}

	@Override
	public void endContact(Body bodyA, Body bodyB, Vector2 normal,
			Vector2[] points) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		mSprite.detachSelf();
		mBody.getWorld().destroyBody(mBody);
		mSprite = null;
		mBody = null;
	}


	@Override
	public float getRotation() {
		return mSprite.getRotation();
	}

	@Override
	public float getX() {
		return mSprite.getX();
	}

	@Override
	public float getY() {
		return mSprite.getY();
	}

}
